package transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component("logdao")
public class LogDAOImpl implements LogDAO {

	static ApplicationContext ctx;
	
	@Autowired
	@Qualifier("jdbcTemplate")
	private JdbcTemplate jdbcTemplate = null;

	
	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}


	@Override
	public void log() {
		java.util.Date dt=new java.util.Date();
		java.sql.Timestamp stamp=new java.sql.Timestamp(dt.getTime());
		String sql="insert into springlog values ('"+stamp.toString()+"','daily note')";
		System.out.println("Sql="+sql);
		jdbcTemplate.execute(sql);
	}
	
	public void logException() throws Exception {
		java.util.Date dt=new java.util.Date();
		java.sql.Timestamp stamp=new java.sql.Timestamp(dt.getTime());
		throw new Exception();
	}

}
